package imgsei.wcj.com.commonbusiness.utils;


import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

import imgsei.wcj.com.commonbusiness.BaseApplication;

/**
 * toast工具
 * @ author LUCKY
 * @ create date 2018/11/7 09:02
 *
 */

public class ToastUtils {
    private static Toast toast;

    /**
     * 显示toast
     * @param context：上下文
     * @param toastMessage：需要显示的文本
     */
    public static void showToast(Context context, String toastMessage) {

        if (toast == null) {
            toast = Toast.makeText(context,toastMessage,Toast.LENGTH_SHORT);
        }
        toast.setText(toastMessage);
        toast.show();
    }

    /**
     * 显示toast
     * @param toastMessage：需要显示的文本
     */
    public static void showToast(String toastMessage){
        showToast(BaseApplication.getInstance(),toastMessage);
    }

    /**
     * 子线程显示toast
     * @param activity：主线程对象
     * @param toastMessage：需要显示的文本
     */
    public static void showToastOfThread(Activity activity, final String toastMessage){
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(toastMessage);
            }
        });
    }

}
